package com.qys.livesMall.quartz.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.quartz.domain.SysJobLog;
import com.qys.livesMall.quartz.service.ISysJobLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调度日志操作处理
 *
 * @author wanglei
 */
@RestController
@Tag(name = "后台管理-定时任务调度日志")
@RequestMapping("/sys/monitor/jobLog")
public class SysJobLogController {
    @Autowired
    private ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @PostMapping("/list")
    @Operation(summary = "查询定时任务调度日志列表")
    public R<Page<SysJobLog>> list(@RequestBody SysJobLog sysJobLog) {
        Page<SysJobLog> page=new Page<>(sysJobLog.getPageNum(),sysJobLog.getPageSize());
        List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
        page.setRecords(list);
        return R.ok(page);
    }

    /**
     * 根据调度编号获取详细信息
     */
    @GetMapping(value = "/{jobLogId}")
    @Operation(summary = "根据调度编号获取详细信息")
    public R<SysJobLog> getInfo(@PathVariable Long jobLogId) {
        return R.ok(jobLogService.selectJobLogById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */
    @DeleteMapping("/{jobLogIds}")
    @Operation(summary = "删除定时任务调度日志")
    public R<?> remove(@PathVariable Long[] jobLogIds) {
        return jobLogService.deleteJobLogByIds(jobLogIds) > 0 ? R.ok() : R.fail();
    }

    /**
     * 清空定时任务调度日志
     */
    @Operation(summary = "清空定时任务调度日志")
    @DeleteMapping("/clean")
    public R<?> clean() {
        jobLogService.cleanJobLog();
        return R.ok();
    }
}
